package com.zhoukun.nacos.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.sun.deploy.security.BlockedException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.yaml.snakeyaml.tokens.BlockEntryToken;

import java.util.concurrent.TimeUnit;

/**
 * @author zhoukun 86547462@qq.com
 * @version 1.0
 * @date 2020/10/31 23:36
 */
@RestController
@Slf4j
public class SentineController {

    @GetMapping("/getA")
    public String geta() {
        return "AAAAAAAAAAAAAAAAAAAAAA";
    }
    @GetMapping("/getB")
    public String getb() throws InterruptedException {

       // TimeUnit.SECONDS.sleep(1);
        int i=10/0;
        return "BBBBBBBBBBBBBBBBBBBBB";
    }
    @GetMapping("/getHostKey")
    @SentinelResource(value = "getHostKey",blockHandler = "block_getHostKey")
    public String getHostKey(@RequestParam(required = false) String v1,
                             @RequestParam(required = false) String v2) {


        return "HostKey:"+v1+v2;
    }
    public String block_getHostKey(String v1, String v2, BlockException exception) {


        return "HostKey:"+v1+v2;
    }


}
